package de.dailab.graphworld.bean;

import de.dailab.graphworld.ontology.Node;
import de.dailab.graphworld.world.ExtendedGraphWorldAgentBean;
import de.dailab.jiactng.agentcore.action.ActionResult;

/**
 *
 * @author Kseniya
 */
public class Scout extends ContestMember {

    @Override
    protected void doExecute() {
        // do the next move the planned route is not explored yet
        if (!route.isEmpty()) {
            move(route.peek());
            return;
        }
        super.doExecute();
    }

    @Override
    public void receiveResult(ActionResult result) {
        super.receiveResult(result);
        if (result.getFailure() == null) {
            switch (result.getAction().getName()) {
                case ExtendedGraphWorldAgentBean.ACTION_INIT_TEAM_POSITION:
                    move(route.element());
                    break;
                default:
                    break;
            }
        }
    }

    @Override
    protected void consumeMove(Node movedTo) {
        super.consumeMove(movedTo);
        if (!route.isEmpty()) {
            route.poll();
        }
        explore();
    }

    @Override
    protected boolean canPerformNextActionImmediately() {
        return !route.isEmpty() ? false : super.canPerformNextActionImmediately();
    }
}
